package cn.itbox.example.application.test;


import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * @BelongProject springboot-study
 * @BelongPackage cn.itbox.example.application.test
 * @Description TODO
 * @ClassName NetNamePrint
 * @Author huyanbing
 * @Date 2024/3/14 15:03
 * @Version 1.0.0
 */
public class NetNamePrint {


    public static void main(String[] args) {
        try {
            // 获取所有网络接口
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            while (interfaces.hasMoreElements()) {
                NetworkInterface networkInterface = interfaces.nextElement();
                // 确保网络接口已经启用
                if (networkInterface.isUp()) {
                    System.out.println("网卡名称: " + networkInterface.getDisplayName());

                    networkInterface.getInetAddresses();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
